/**
 * Created by jt on 2017/5/8.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";
import projResultTpl from "./proj-result.handlebars";

var projId = getArgs().id;
var token = sessionStorage.getItem('token');
if (token == null || token =='') {
    location.href = HOST_FRT+'/logins/login.html';
}

var bidResult = {
    init: function(){
        this.getResultData()
            .then(this.renderbidResult)
    },
    getResultData: function() {
        return new Promise((resolve, reject)=>{
            let self = this;
            $.ajax({
                url: HOST_ADDR + `/cpmp/xjProjMngForPchs/viewAwdInf/`+projId,
                type: 'get',
                dataType: 'json',
                headers: {
                    'access_token': token,'login_type':'ums'
                },
                // data:JSON.stringify(data),
                contentType: "application/json",
                success: function (resp) {
                    if (resp.success) {
                        console.log(resp);
                        resolve(resp);
                    }
                    else {
                        alert(resp.msgInf);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });

        });

    },
    // 渲染列表
    renderbidResult: function(resp){
        $.each(resp.data,function(index,item){
            item.untPriFmt = item.untPri + "("+item.currTyp+")";
            item.ttlPriFmt = item.ttlPri + "("+item.currTyp+")";
        });
        let resultHtml = projResultTpl({bidResult: resp.data});
        $('.setInfo').append(resultHtml);
    },

    // 渲染列表
    renderList(){
        this.getResultData()
            .then(this.renderbidResult)
    }
};

App.init();
bidResult.init();

jQuery('.logOut').attr('href','../logins/login.html');